<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打印票据 - 航空订票系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css">
    <style>
        body {
            background-color: #fff;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        .ticket-container {
            max-width: 800px;
            margin: 20px auto;
            border: 1px solid #ddd;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .ticket-header {
            border-bottom: 2px solid #007bff;
            padding-bottom: 10px;
            margin-bottom: 20px;
        }
        .ticket-logo {
            font-size: 24px;
            font-weight: bold;
        }
        .ticket-info {
            margin-bottom: 20px;
        }
        .ticket-route {
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 30px 0;
        }
        .ticket-city {
            font-size: 24px;
            font-weight: bold;
        }
        .ticket-flight {
            margin: 0 20px;
        }
        .ticket-details {
            margin-top: 20px;
        }
        .ticket-footer {
            margin-top: 30px;
            border-top: 1px dashed #ddd;
            padding-top: 15px;
            font-size: 12px;
        }
        .barcode {
            height: 60px;
            background: repeating-linear-gradient(90deg, #000, #000 2px, #fff 2px, #fff 4px);
            margin: 20px 0;
        }
        .print-only {
            display: none;
        }
        @media print {
            .no-print {
                display: none;
            }
            .print-only {
                display: block;
            }
            body {
                padding: 0;
                margin: 0;
            }
            .ticket-container {
                box-shadow: none;
                border: none;
                padding: 0;
                margin: 0;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="no-print text-center mt-3">
            <button onclick="window.print()" class="btn btn-primary"><i class="fas fa-print mr-2"></i>打印此页</button>
            <a th:href="@{/tickets/{id}(id=${ticket.ticketId})}" class="btn btn-secondary ml-2"><i class="fas fa-arrow-left mr-2"></i>返回详情</a>
        </div>
        
        <div class="ticket-container">
            <div class="ticket-header d-flex justify-content-between align-items-center">
                <div class="ticket-logo">
                    <i class="fas fa-plane-departure mr-2"></i>航空订票系统
                </div>
                <div>
                    <h4>电子机票</h4>
                    <div class="text-muted">E-TICKET</div>
                </div>
            </div>
            
            <div class="ticket-info">
                <div class="row">
                    <div class="col-md-6">
                        <strong>票号：</strong> <span th:text="${ticket.ticketId}">1234</span>
                    </div>
                    <div class="col-md-6 text-md-right">
                        <strong>状态：</strong> 
                        <span th:if="${ticket.status == '已预订'}" class="badge badge-warning">已预订</span>
                        <span th:if="${ticket.status == '已出票'}" class="badge badge-success">已出票</span>
                        <span th:if="${ticket.status == '已取消'}" class="badge badge-danger">已取消</span>
                        <span th:if="${ticket.status == '已退票'}" class="badge badge-secondary">已退票</span>
                        <span th:if="${ticket.status == '已使用'}" class="badge badge-info">已使用</span>
                    </div>
                </div>
            </div>
            
            <div class="ticket-route">
                <div class="text-center">
                    <div class="ticket-city" th:text="${ticket.flight != null ? ticket.flight.departureCity : '未知'}">北京</div>
                    <div class="text-muted" th:text="${ticket.flight != null ? #dates.format(ticket.flight.departureTime, 'HH:mm') : '未知'}">08:00</div>
                </div>
                <div class="ticket-flight">
                    <div class="text-center">
                        <i class="fas fa-plane text-primary" style="font-size: 24px;"></i>
                        <div class="mt-2">
                            <span class="badge badge-light" th:text="${ticket.flightId}">CA1234</span>
                        </div>
                    </div>
                </div>
                <div class="text-center">
                    <div class="ticket-city" th:text="${ticket.flight != null ? ticket.flight.arrivalCity : '未知'}">上海</div>
                    <div class="text-muted" th:text="${ticket.flight != null ? #dates.format(ticket.flight.arrivalTime, 'HH:mm') : '未知'}">10:00</div>
                </div>
            </div>
            
            <div class="ticket-details">
                <div class="row">
                    <div class="col-md-6">
                        <h5>航班信息</h5>
                        <table class="table table-sm">
                            <tr>
                                <th>航班号</th>
                                <td th:text="${ticket.flightId}">CA1234</td>
                            </tr>
                            <tr>
                                <th>航空公司</th>
                                <td th:text="${ticket.flight != null ? ticket.flight.airlineCompany : '未知'}">中国国际航空</td>
                            </tr>
                            <tr>
                                <th>出发日期</th>
                                <td th:text="${ticket.flight != null ? #dates.format(ticket.flight.departureTime, 'yyyy-MM-dd') : '未知'}">2023-07-01</td>
                            </tr>
                            <tr>
                                <th>出发时间</th>
                                <td th:text="${ticket.flight != null ? #dates.format(ticket.flight.departureTime, 'HH:mm') : '未知'}">08:00</td>
                            </tr>
                            <tr>
                                <th>到达时间</th>
                                <td th:text="${ticket.flight != null ? #dates.format(ticket.flight.arrivalTime, 'HH:mm') : '未知'}">10:00</td>
                            </tr>
                            <tr>
                                <th>座位号</th>
                                <td th:text="${ticket.seatNumber}">12A</td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <h5>旅客信息</h5>
                        <table class="table table-sm" th:if="${ticket.passenger != null}">
                            <tr>
                                <th>姓名</th>
                                <td th:text="${ticket.passenger.name}">张三</td>
                            </tr>
                            <tr>
                                <th>身份证</th>
                                <td th:text="${ticket.passenger.idCard}">110101199001010000</td>
                            </tr>
                            <tr>
                                <th>联系电话</th>
                                <td th:text="${ticket.passenger.phone}">13800138000</td>
                            </tr>
                        </table>
                        <div class="alert alert-warning" th:if="${ticket.passenger == null}">
                            未关联旅客信息
                        </div>
                        
                        <h5 class="mt-4">票价信息</h5>
                        <table class="table table-sm">
                            <tr>
                                <th>原价</th>
                                <td th:text="${ticket.flight != null ? ticket.flight.basePrice + '元' : '未知'}">1500.00元</td>
                            </tr>
                            <tr>
                                <th>折扣</th>
                                <td th:text="${ticket.passenger != null && ticket.passenger.vipDiscount != null ? ticket.passenger.vipDiscount.multiply(new java.math.BigDecimal('100')) + '%' : '无折扣'}">80%</td>
                            </tr>
                            <tr>
                                <th>实付金额</th>
                                <td><strong th:text="${ticket.actualPrice + '元'}" class="text-danger">1200.00元</strong></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            
            <div class="barcode"></div>
            
            <div class="ticket-footer text-center">
                <p>本电子票据由航空订票系统自动生成，打印日期：<span th:text="${#dates.format(#dates.createNow(), 'yyyy-MM-dd HH:mm:ss')}">2023-07-01 12:00:00</span></p>
                <p class="text-muted">© 2025 航空订票系统 - JZA04</p>
            </div>
        </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 自动打印功能（可选）
        /*
        window.onload = function() {
            setTimeout(function() {
                window.print();
            }, 1000);
        };
        */
    </script>
</body>
</html>